
package boids;

import java.util.ArrayList;
import java.util.Date;


import processing.core.PGraphics;
import toolib.geom.Spline2D;
import toolib.geom.V2f;
import toxi.geom.Vec2D;
import toxi.math.MathUtils;

public class SplinePath extends Spline2D implements Path
{
	private float radius;
	
	public SplinePath(float _radius, String _type)
	{
		super();
		
		if (_type != BEZIER && _type != CUBIC && _type != LAGRANGE)
		{

			throw new IllegalArgumentException("Unknown spline type.");
		}
		type(_type);
		
		radius = _radius;
	}
	
	public SplinePath(ArrayList<Vec2D> _cpoints, float _radius, String _type)
	{
		super();
		
		if (_type != BEZIER && _type != CUBIC && _type != LAGRANGE)
		{

			throw new IllegalArgumentException("Unknown spline type.");
		}
		type(_type);
		
		for (int i = 0; i < _cpoints.size(); i++)
		{
			addPoint(_cpoints.get(i).x, _cpoints.get(i).y);
		}
		
		radius = _radius;
	}

	public void render(PGraphics _g)
	{
		_g.noFill();
		_g.stroke(255.0f, 0.0f, 0.0f);
		_g.beginShape();
		for (int i = 0; i < vertices().length; i++)
		{
			V2f v = vertices()[i];
			_g.vertex(v.x, v.y);
		}
		_g.endShape();
		
		_g.noStroke();
		_g.fill(255.0f);
		for (int i = 0; i < getNumPoints(); i++)
		{
			Vec2D p = getPoint(i);
			_g.ellipse(p.x, p.y, 4, 4);
		}
	}

	public void addPoint(Vec2D _point)
	{
		addPoint(_point.x, _point.y);
	}

	public void clear()
	{
		clearPoints();
	}

	public Vec2D getEnd()
	{
		V2f end = points().get(points().size()-1);
		return new Vec2D(end.x, end.y);
	}

	public int getNumPoints()
	{
		return points().size();
	}

	public Vec2D getPoint(int _i)
	{
		V2f point = points().get(_i);
		return new Vec2D(point.x, point.y);
	}

	public ArrayList<Vec2D> getPoints()
	{
		ArrayList<Vec2D> points = new ArrayList<Vec2D>();
		for (int i = 0; i < points().size(); i++)
		{
			points.add(new Vec2D(points().get(i).x, points().get(i).y));
		}
		return points;
	}

	public float getRadius()
	{
		return radius;
	}

	public Vec2D getStart()
	{
		V2f start = points().get(0);
		return new Vec2D(start.x, start.y);
	}

	public void setRadius(float _radius)
	{
		radius = _radius;
	}
}
